package example.documentbased.editorModule.controller
{
	import example.documentbased.editorModule.common.MenuItem;
	import example.documentbased.mainModule.controller.RefreshAllCommand;
	import example.documentbased.mainModule.models.vo.DocumentVO;
	import example.documentbased.mainModule.models.vo.EditorVO;
	
	import org.etherframework.common.command.ICommand;
	import org.etherframework.controller.Controller;
	import org.etherframework.controller.IReactiveCommand;
	import org.etherframework.core.context.Context;
	import org.etherframework.core.context.Default;
	
	public final class EditorController extends Controller implements IEditorController
	{
		public function withData(data:*):IEditorController
		{
			var controller:IEditorController = 
				contextual(new Default(data), IEditorController) as IEditorController;
			
			return controller;
		}
		
		public function withContext(context:Context):IEditorController
		{
			var controller:IEditorController = 
				contextual(context, IEditorController) as IEditorController;
			
			return controller;
		}
		
		public function getSetEditorCommand(editor:EditorVO):IReactiveCommand
		{
			var cmd:SetEditorCommand = command(SetEditorCommand) as SetEditorCommand;
			return cmd.initialize(editor);
		}
		
		public function getCreateDocumentCommand():IReactiveCommand
		{
			return command(CreateDocumentCommand) as CreateDocumentCommand;
		}
		
		public function getEditDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:EditDocumentCommand = command(EditDocumentCommand) as EditDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getUpdateDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:UpdateDocumentCommand = command(UpdateDocumentCommand) as UpdateDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getCloseDocumentCommand(document:DocumentVO, isSafe:Boolean = true):IReactiveCommand
		{
			var cmd:CloseDocumentCommand = command(CloseDocumentCommand) as CloseDocumentCommand;
			return cmd.initialize(document, isSafe);
		}
		
		public function getOpenDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:OpenDocumentCommand = command(OpenDocumentCommand) as OpenDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getSelectDocumentCommand():IReactiveCommand
		{
			return command(SelectDocumentCommand) as SelectDocumentCommand;
		}
		
		public function getSetCurrentDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:SetCurrentDocumentCommand = command(SetCurrentDocumentCommand) as SetCurrentDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getSaveDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:SaveDocumentCommand = command(SaveDocumentCommand) as SaveDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getSaveAsDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:SaveAsDocumentCommand = command(SaveAsDocumentCommand) as SaveAsDocumentCommand;
			return cmd.initialize(document);
		}
		
		public function getCloseAllDocumentsCommand():IReactiveCommand
		{
			return command(CloseAllDocumentsCommand) as CloseAllDocumentsCommand;
		}
		
		public function getSaveAllDocumentsCommand():IReactiveCommand
		{
			return command(SaveAllDocumentsCommand) as SaveAllDocumentsCommand;
		}
		
		public function getSaveEditorCommand(editor:EditorVO):IReactiveCommand
		{
			var cmd:SaveEditorCommand = command(SaveEditorCommand) as SaveEditorCommand;
			return cmd.initialize(editor);
		}
		
		public function getChangeEditorNameCommand(editor:EditorVO):IReactiveCommand
		{
			var cmd:ChangeEditorNameCommand = command(ChangeEditorNameCommand) as ChangeEditorNameCommand;
			return cmd.initialize(editor);
		}
		
		public function getRefreshAllCommand():IReactiveCommand
		{
			return command(RefreshAllCommand) as RefreshAllCommand;
		}
		
		public function getApplyMenyItemCommand(item:MenuItem):IReactiveCommand
		{
			var cmd:ApplyMenyItemCommand = command(ApplyMenyItemCommand) as ApplyMenyItemCommand;
			return cmd.initialize(item);
		}
		
		public function getUpdateEditorMenuCommand():ICommand
		{
			return command(UpdateEditorMenuCommand);
		}
		
		public function getDeleteDocumentCommand(document:DocumentVO):IReactiveCommand
		{
			var cmd:DeleteDocumentCommand = command(DeleteDocumentCommand) as DeleteDocumentCommand;
			return cmd.initialize(document);
		}
	}
}